package com.pj.point.util;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.widget.Toast;

import com.pj.point.receiver.AlertReceiver;

import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class AlarmManagerUtil {
     public static void addAlarm(Context context, Calendar time,Intent intent){

          time.set(Calendar.SECOND,0);
          time.set(Calendar.MILLISECOND,0);
          System.out.println(Util.getTime(new Date(System.currentTimeMillis())));
          PendingIntent broadcast = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
          AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
          manager.set(AlarmManager.RTC_WAKEUP,time.getTimeInMillis(),broadcast);
          Toast.makeText(context, "设置提醒成功！", Toast.LENGTH_SHORT).show();
          Toast.makeText(context, Util.getTime(time.getTime()), Toast.LENGTH_SHORT).show();
          System.out.println(Util.getTime(time.getTime()));
     }

     public static void stopRemind(Context context,Intent intent) {

          PendingIntent pi = PendingIntent.getBroadcast(context, 0,
                  intent, 0);
          AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
          //取消警报
          am.cancel(pi);
          Toast.makeText(context, "关闭了提醒", Toast.LENGTH_SHORT).show();

     }

}
